<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../static/layer/css/layui.css" media="all"/>
    <!--<link rel="stylesheet" href="../../../static/ucss/hydropower/water_electricity_edit.css">-->
    <!--<link rel="stylesheet" href="../../../static/ucss/contract/contract.css"/>-->
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item panel-code">
        <label class="layui-form-label">电表编号：</label>
        <div class="layui-input-block">
            <input type="text" name="code" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item panel-rates">
        <label class="layui-form-label">电表倍率：</label>
        <div class="layui-input-block">
            <input type="text" name="rates" placeholder="请输入电表倍率" autocomplete="off"
                   class="layui-input" value="1">
        </div>
    </div>
    <div class="layui-form-item panel-last">
        <label class="layui-form-label">上月读数：</label>
        <div class="layui-input-block">
            <input type="text" name="lastCount"  autocomplete="off"
                   class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item panel-dates">
        <label class="layui-form-label">抄表时间：</label>
        <div class="layui-input-block">
            <input type="text" name="date" autocomplete="off"
                   class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item panel-new">
        <label class="layui-form-label">新表读数：</label>
        <div class="layui-input-block">
            <input type="text" name="newCounts"  autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item panel-remarks">
        <label class="layui-form-label">备注：</label>
        <div class="layui-input-block">
            <input type="text" name="remarks" placeholder="请输入备注信息" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="electricity">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="../../../static/js/common/queryUtils.js"></script>
<script type="text/javascript" src="../../../static/layer/layui.js"></script>
<script>
    var $;
    var form;
    var did = "";
    var type = 0;
    layui.use(['jquery', 'form', 'layer'], function () {
        $ = layui.jquery;
        form = layui.form;
        var layer = layui.layer;

        var t = QueryUtils.GetQueryString("t");
        var id = QueryUtils.GetQueryString("id");//水电表ID
        if(t == 0){
            $(".panel-code").find("label").html("电表编号：");
        }else {
            $(".panel-code").find("label").html("水表编号：");
        }

        $.ajax({
            type: "post",
            url: "/hydropower/findforchange",
            async: false,
            data: {
                id:id
            },
            success: function(rs) {
                if(rs.errcode == "00"){
                    var data = rs.data;
                    did = data.DID;
                    $(".panel-code").find("div").find("input").val(data.CODE);
                    $(".panel-rates").find("div").find("input").val(data.RATES);
                    $(".panel-remarks").find("div").find("input").val(data.REMARKS);
                    if(data.CUR_DEGREES != 0){
                        type = 0;
                        $(".panel-last").find("div").find("input").val(data.CUR_DEGREES);
                        $(".panel-dates").find("div").find("input").val(data.CUR_DATE);
                    }else {
                        type = 1;
                        $(".panel-last").find("div").find("input").val(data.LAST_DEGREES);
                        $(".panel-dates").find("div").find("input").val(data.LAST_DATE);
                    }
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {}
        });

        form.on('submit(electricity)',function (data) {
            data.field.id = id;
            data.field.did =did;
            data.field.tp = type;
            var tips;
            if(t == 0){
                tips = "确定更换电表吗";
            }else {
                tips = "确定更换水表吗";
            }
            layer.msg(tips, {
                time: 0
                , btn: ['确定', '取消']
                , shade: 0.3
                , yes: function (index) {
                    layer.close(index);
                    $.ajax({
                        url: "/hydropower/change",
                        data: data.field,
                        dataType: "json",
                        type: "post",
                        async: false,
                        success: function (res) {
                            if (res.errcode === "00") {
                                var i = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(i);
                                if(t == 0){
                                    parent.initEleTable();
                                }else {
                                    parent.initWatTable();
                                }
                                parent.getPowerInfo(t,id);
                                parent.layer.msg("更换成功", {offset: '150px'});
                            } else if (res.errcode === "01") {
                                layer.msg(res.errmsg, function () {
                                });
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.error(XMLHttpRequest.status);
                            console.error(XMLHttpRequest.readyState);
                            console.error(textStatus);
                        }
                    });
                }
            });
            return false;
        })
    })
</script>
</body>
</html>